﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Text;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Database;
using ReflectionStudio.Core.Events;
using System.Windows.Controls;
using System.Windows.Forms;
namespace WPFExcelReport
{

    public class ARTICLEMASTERData : BaseFunction
    {

        string TrisInclude = "";
        GreigeMasterData m_GM;
        public ARTICLEMASTERData()
            : base()
        {
        }
        public ARTICLEMASTERData(OracleConnection _OracleDB, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_OracleDB, _proxy, userID)
        {
            m_GM = new GreigeMasterData(OracleDB, proxy, UserID);
        }
        public ARTICLEMASTERData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
            m_GM = new GreigeMasterData(OracleDB, proxy, UserID);
        }
        public DataSet ListWAFARBEN(DataRow dwWASTAMM)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            try
            {
                OracleCommand or1 = OracleDB.CreateCommand();
                #region
                or1.CommandText = "SELECT * FROM WAFARBEN"
                + " WHERE WAFART =: WAFART AND WAFVAR=:WAFVAR";
                or1.Parameters.Add("WAFART", OracleType.NVarChar).Value = dwWASTAMM["WAART"].ToString();
                or1.Parameters.Add("WAFVAR", OracleType.NVarChar).Value = dwWASTAMM["WAVAR"].ToString();
                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "WAFARBEN";
                    byte[] b;
                    string value;
                    string sTemp = "";
                    string Column = "";
                    foreach (DataRow dwTemp in tableLocal.Rows)
                    {
                        Column = "WAFZUSATZ";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                    }
                    setReturn.Merge(setResult);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet QueryWASTAMM(DataRow dwWASTAMM)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            OracleCommand or1;
            try
            {
                string WANEUB, WAART, WAVAR="  ";
                WANEUB = dwWASTAMM["WANEUB"].ToString();
                WAART = dwWASTAMM["WAART"].ToString();
                WAVAR = dwWASTAMM["WAVAR"].ToString();

                #region
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM WASTAMM"
                + " WHERE WAART = '" + WAART + "' AND WAVAR='" + WAVAR + "'"
                + " ORDER BY 1,2,3,4";
                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "WASTAMM";
                }
                
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet QueryVKPOS(DataRow dwInput)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            OracleCommand or1;
            string VK04 = dwInput["VKPAUFKRS"].ToString()
                + "/" + dwInput["VKPAUFLFD"].ToString() 
                + "/" + dwInput["VKPAUFPOS"].ToString();
            try
            {
                #region================VKPOS===================
                EventDispatcher.Instance.RaiseStatus("客单" + VK04 + "开始读取信息", StatusEventType.StartProgress); 
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM VKPOS "
                + " WHERE VKPMANDANT='00' AND VKPSA='  ' "
                + " AND VKPAUFKRS=:VKPAUFKRS AND VKPAUFLFD=:VKPAUFLFD AND VKPAUFPOS=:VKPAUFPOS";

                or1.Parameters.Add("VKPAUFKRS", OracleType.NVarChar).Value = dwInput["VKPAUFKRS"].ToString();
                or1.Parameters.Add("VKPAUFLFD", OracleType.NVarChar).Value = dwInput["VKPAUFLFD"].ToString();
                or1.Parameters.Add("VKPAUFPOS", OracleType.NVarChar).Value = dwInput["VKPAUFPOS"].ToString();
                setResult = Connect2Proxy(or1);
                #endregion
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "VKPOS";
                    setReturn.Merge(setResult);
                    byte[] b;
                    string value;
                    string sTemp = "";
                    string Column = "";
                    foreach (DataRow dwTemp in tableLocal.Rows)
                    {
                        setResult = QueryVA0710(dwTemp);
                        EventDispatcher.Instance.RaiseStatus("客单" + VK04 + "读取品种信息", StatusEventType.StartProgress); 
                        setReturn.Merge(setResult);
                        DataRow dwVAFARBEN = setResult.Tables["VAFARBEN"].Rows[0];
                        setResult = QueryWDECK(dwTemp, dwVAFARBEN, "K", "00", true);
                        EventDispatcher.Instance.RaiseStatus("客单" + VK04 + "读取可用性信息", StatusEventType.StartProgress); 
                        setReturn.Merge(setResult);
                    }
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet QueryVA0710(DataRow dwVKPOS)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            OracleCommand or1;
            try
            {
                #region
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM VAART "
                + " WHERE VAAMANDANT=:VAAMANDANT AND VAAKOLL=:VAAKOLL AND VAAART=:VAAART";

                or1.Parameters.Add("VAAMANDANT", OracleType.NVarChar).Value = dwVKPOS["VKPMANDANT"];
                or1.Parameters.Add("VAAKOLL", OracleType.NVarChar).Value = dwVKPOS["VKPKOLL"];
                or1.Parameters.Add("VAAART", OracleType.NVarChar).Value = dwVKPOS["VKPART"];

                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "VAART";
                }
                setReturn.Merge(setResult);
                #endregion

                #region
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM VAFARBEN "
                + " WHERE VAFMANDANT=:VAFMANDANT AND VAFKOLL=:VAFKOLL AND VAFART=:VAFART AND VAFFARBE=:VAFFARBE";

                or1.Parameters.Add("VAFMANDANT", OracleType.NVarChar).Value = dwVKPOS["VKPMANDANT"];
                or1.Parameters.Add("VAFKOLL", OracleType.NVarChar).Value = dwVKPOS["VKPKOLL"];
                or1.Parameters.Add("VAFART", OracleType.NVarChar).Value = dwVKPOS["VKPART"];
                or1.Parameters.Add("VAFFARBE", OracleType.NVarChar).Value = dwVKPOS["VKPFARBE"];

                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "VAFARBEN";
                }
                setReturn.Merge(setResult);
                #endregion
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet QueryWDECK(DataRow dwVKPOS, DataRow dwVAFARBEN, string WDSA = "K", string WDUPOS = "00", bool flagCreate = true)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;

            OracleCommand or1;
            try
            {
                #region==================SELECT=================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM WDECK "
                + " WHERE WDMANDANT=:WDMANDANT AND WDSA=:WDSA AND WDUPOS=:WDUPOS "
                + " AND WDAUFKRS=:WDAUFKRS AND WDAUFLFD=:WDAUFLFD AND WDAUFPOS=:WDAUFPOS";

                or1.Parameters.Add("WDMANDANT", OracleType.NVarChar).Value = dwVKPOS["VKPMANDANT"];
                or1.Parameters.Add("WDSA", OracleType.NVarChar).Value = WDSA;
                or1.Parameters.Add("WDUPOS", OracleType.NVarChar).Value = WDUPOS;
                or1.Parameters.Add("WDAUFKRS", OracleType.NVarChar).Value = dwVKPOS["VKPAUFKRS"];
                or1.Parameters.Add("WDAUFLFD", OracleType.NVarChar).Value = dwVKPOS["VKPAUFLFD"];
                or1.Parameters.Add("WDAUFPOS", OracleType.NVarChar).Value = dwVKPOS["VKPAUFPOS"];
                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "WDECK";
                }
                #region==================INSERT=================
                if (flagCreate && tableLocal.Rows.Count == 0)
                {

                    or1 = OracleDB.CreateCommand();
                    or1.CommandText = "INSERT INTO WDECK(WDMANDANT, WDSA, WDAUFKRS, WDAUFLFD, WDAUFPOS, WDTYP, WDUPOS, WDKUNDNR, WDWERK, WDABT, WDWAKZ, WDART, WDDESS, WDCOLORIT, WDFARBE, WDBESCHICH, WDVAR, WDZUSTAND, WDDAT, WDLO, WDZS, WDAFOLGE, WDBEDARF, WDZUGET, WDRESERV, WDVERBR, WDANZSTK, WDKZBEDARF, WDURAUFKRS, WDURAUFLFD, WDURAUFPOS, WDVKNPOS, WDPGLKZ, WDABRKZ, WDDISPOKZ, WDERLKZ, WDSLPOS, WDPRART, WDPRVAR, WDBEDBAS, WDLAGE, WDVARFR, WDBEDST, WDFILLER)"
                                    + "VALUES (:WDMANDANT, :WDSA, :WDAUFKRS, :WDAUFLFD, :WDAUFPOS, 'B', :WDUPOS, '00000000', '   ', '   ', 'F', :WDART, :WDDESS,:WDCOLORIT, :WDFARBE,:WDBESCHICH,:WDVAR, '    ', :WDDAT, '  ', ' ', '000', 0, 0, 0, 0, '000', ' ', '  ', '000000', '000', 0, ' ', ' ', ' ', ' ', 0, '                    ', '  ', '00000000', '00', ' ', ' ', '000000000      ')";

                    or1.Parameters.Add("WDMANDANT", OracleType.NVarChar).Value = dwVKPOS["VKPMANDANT"];
                    or1.Parameters.Add("WDSA", OracleType.NVarChar).Value = WDSA;
                    or1.Parameters.Add("WDUPOS", OracleType.NVarChar).Value = WDUPOS;
                    or1.Parameters.Add("WDAUFKRS", OracleType.NVarChar).Value = dwVKPOS["VKPAUFKRS"];
                    or1.Parameters.Add("WDAUFLFD", OracleType.NVarChar).Value = dwVKPOS["VKPAUFLFD"];
                    or1.Parameters.Add("WDAUFPOS", OracleType.NVarChar).Value = dwVKPOS["VKPAUFPOS"];
                    or1.Parameters.Add("WDART", OracleType.NVarChar).Value = dwVAFARBEN["VAFPART"];
                    or1.Parameters.Add("WDVAR", OracleType.NVarChar).Value = dwVAFARBEN["VAFPVAR"];
                    or1.Parameters.Add("WDDESS", OracleType.NVarChar).Value = dwVAFARBEN["VAFDESS"];
                    or1.Parameters.Add("WDCOLORIT", OracleType.NVarChar).Value = dwVAFARBEN["VAFCOLORIT"];
                    or1.Parameters.Add("WDFARBE", OracleType.NVarChar).Value = dwVAFARBEN["VAFFFARBE"];
                    or1.Parameters.Add("WDBESCHICH", OracleType.NVarChar).Value = dwVAFARBEN["VAFBESCHICH"];
                    or1.Parameters.Add("WDDAT", OracleType.NVarChar).Value = dwVKPOS["VKPLIEFTERM"];

                    setResult = Connect2Proxy(or1);
                    #region==================SELECT=================
                    or1 = OracleDB.CreateCommand();
                    or1.CommandText = "SELECT * FROM WDECK "
                    + " WHERE WDMANDANT=:WDMANDANT AND WDSA=:WDSA AND WDUPOS=:WDUPOS "
                    + " AND WDAUFKRS=:WDAUFKRS AND WDAUFLFD=:WDAUFLFD AND WDAUFPOS=:WDAUFPOS";

                    or1.Parameters.Add("WDMANDANT", OracleType.NVarChar).Value = dwVKPOS["VKPMANDANT"];
                    or1.Parameters.Add("WDSA", OracleType.NVarChar).Value = WDSA;
                    or1.Parameters.Add("WDUPOS", OracleType.NVarChar).Value = WDUPOS;
                    or1.Parameters.Add("WDAUFKRS", OracleType.NVarChar).Value = dwVKPOS["VKPAUFKRS"];
                    or1.Parameters.Add("WDAUFLFD", OracleType.NVarChar).Value = dwVKPOS["VKPAUFLFD"];
                    or1.Parameters.Add("WDAUFPOS", OracleType.NVarChar).Value = dwVKPOS["VKPAUFPOS"];

                    setResult = Connect2Proxy(or1);
                    #endregion
                }
                #endregion
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        
        public DataSet ListGSDAT()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            try
            {
                OracleCommand or1 = OracleDB.CreateCommand();
                #region
                or1.CommandText = "SELECT DISTINCT GSART,GSVAR,GSGARNBEZ FROM GSDAT "
                + " ORDER BY 1,2";
                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "GSDAT";
                    byte[] b;
                    string value;
                    string sTemp = "";
                    string Column = "";
                    setReturn.Merge(setResult);
                }
              
                EventDispatcher.Instance.RaiseStatus( "查询GSDAT完成", StatusEventType.RunningProgress); 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }

        public DataSet ListWTSCHUSS()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            try
            {
                OracleCommand or1 = OracleDB.CreateCommand();
                #region
                or1.CommandText = "SELECT * FROM WTSCHUSS "
                + " ORDER BY 1,2,3,4";
                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "WTSCHUSS";
                    byte[] b;
                    string value;
                    string sTemp = "";
                    string Column = "";
                    foreach (DataRow dwTemp in tableLocal.Rows)
                    {
                        Column = "WTSSFLGNR";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        Column = "WTSBEZ";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        setTemp = ListWAFARBEN(dwTemp);
                        setReturn.Merge(setTemp);
                    }
                    setReturn.Merge(setResult);
                }
                EventDispatcher.Instance.RaiseStatus("查询WTSCHUSS完成", StatusEventType.RunningProgress); 
               
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet ListWTSAER()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            try
            {
                OracleCommand or1 = OracleDB.CreateCommand();
                #region
                or1.CommandText = "SELECT * FROM WTSAER "
                + " ORDER BY 1,2,3,4";
                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "WTSAER";
                    byte[] b;
                    string value;
                    string sTemp = "";
                    string Column = "";
                    foreach (DataRow dwTemp in tableLocal.Rows)
                    {
                        Column = "WTBSRFNR";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        Column = "WTBBEZ";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        setTemp = ListWAFARBEN(dwTemp);
                        setReturn.Merge(setTemp);
                    }
                    setReturn.Merge(setResult);
                    EventDispatcher.Instance.RaiseStatus("查询WTSAER完成", StatusEventType.RunningProgress); 
              
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetRWABIND()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT DISTINCT SDSA,SUBSTR(SDKEY,3,15) AS WABINDKEY,SUBSTR(SDDATEN,2,49) AS DESCRIPTION"
                + " FROM SDDAT WHERE SDSA='0109' AND SDKEY LIKE '00%' AND SDKEY LIKE '%V' ORDER BY 1,2,3";
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WABIND";
                }
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("查询WABIND完成", StatusEventType.RunningProgress); 
              
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetRWTPASS()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT * FROM WTPASS WHERE WTPMANDANT='00'";
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WTPASS";
                }
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("查询WTPASS完成", StatusEventType.RunningProgress); 
           
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetRWADART()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT DISTINCT WADART,WADVAR FROM WASTAMM WHERE WAMANDANT='00'";
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WADART";
                }
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("查询WADART完成", StatusEventType.RunningProgress); 
            
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }

        public DataSet GetRWTEINZ()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT * FROM WTEINZ";
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WTEINZ";
                }
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("查询WTEINZ完成", StatusEventType.RunningProgress); 
               
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetWASTAMM(DataRow dwWASTAMM)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            try
            {
                string WANEUB, WAART;
                WANEUB = dwWASTAMM["WANEUB"].ToString();
                WAART = dwWASTAMM["WAART"].ToString().Trim();
                OracleCommand or1 = OracleDB.CreateCommand();
                #region
                or1.CommandText = "SELECT WAART,WAVAR,WABEZ,WARBEM FROM WASTAMM"
                + " WHERE WAART LIKE '%" + WAART + "%'  AND WANEUB='" + WANEUB + "'"
                + " ORDER BY 1,2,3,4";
                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "LISTARTICLE";
                    byte[] b;
                    string value;
                    string sTemp = "";
                    string Column = "";
                    foreach (DataRow dwTemp in tableLocal.Rows)
                    {
                        Column = "WABEZ";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        Column = "WARBEM";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                    }
                    setReturn.Merge(setResult);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet AddBASTGA(DataRow dwBASTGA = null)
        {
            DataSet set4Return = new DataSet();
            DataSet setResult = new DataSet();
            DataTable tableLocal;
            try
            {
                OracleCommand or1 = OracleDB.CreateCommand();
                #region
                or1.CommandText = "SELECT GSART,GSVAR,GSFARBE,GSCBEZ FROM GSCOLOR";
                /*or1.Parameters.Add("BSMANDANT", OracleType.NVarChar).Value = dwBS["BSMANDANT"].ToString();
                or1.Parameters.Add("BSKART", OracleType.NVarChar).Value = dwBS["BSKART"].ToString();
                or1.Parameters.Add("BSNEUBEN", OracleType.NVarChar).Value = dwBS["BSNEUBEN"].ToString();
                or1.Parameters.Add("BSNEUDAT", OracleType.NVarChar).Value = dwBS["BSNEUDAT"].ToString();*/
                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "GSCOLOR";
                    byte[] b;
                    string value;
                    string sTemp = "";
                    string Column = "";
                    string KDKUNDNA;
                    foreach (DataRow dwTemp in tableLocal.Rows)
                    {
                        Column = "GSCBEZ";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        if (value == "")
                        {
                            value = ".";
                        }
                        dwTemp[Column] = value;
                        #endregion
                    }
                }
                set4Return.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return set4Return;
        }
        public DataSet NewWEAVINGBeam(DataSet setData, DataRow dwWAFARBEN, bool IsSectionWarp = false, int SizingBeamYarnEnds = 0, int numWbeam = 1)
        {
            DataSet set4Return = new DataSet();
            DataSet setResult = new DataSet();
            DataTable tableLocal;
            DataRow dwBSSATZ, dwBSFARB, dwBHSATZ;
            string bColor;
            WarpMasterData m_WD = new WarpMasterData(OracleDB, proxy);
            GreigeMasterData m_GD;
            DataRow dwDispo = setData.Tables["DATADISPO"].Rows[0];
            string BSFKART;
            try
            {
                m_WD.UserID = UserID;
                if (IsSectionWarp)//分批整经
                {
                    #region==========BSSATZ========================
                    dwBSFARB = setINTEX.BSFARB.NewRow();
                    BSFKART = Left(dwWAFARBEN["WAFART"].ToString().Trim() + "." + dwWAFARBEN["WAFVAR"].ToString().TrimEnd() + "              ", 20);
                    dwBSFARB["BSFMANDANT"] = dwWAFARBEN["WAFMANDANT"];
                    dwBSFARB["BSFKART"] = BSFKART;
                    dwBSFARB["BSFNEUB"] = dwWAFARBEN["WAFNEUBEN"];
                    dwBSFARB["BSFNEUD"] = dwWAFARBEN["WAFNEUDAT"];
                    dwBSFARB["BSFAENB"] = dwWAFARBEN["WAFNEUBEN"];
                    dwBSFARB["BSFAEND"] = dwWAFARBEN["WAFNEUDAT"];
                    //返回这条记录，放回界面
                    setResult = m_WD.InsertBSSATZ(dwBSFARB, "S", SizingBeamYarnEnds, numWbeam);
                    set4Return.Merge(setResult);
                    #endregion 

                    #region==========BSGROE========================
                    setResult = m_WD.InsertBSGROE(dwBSFARB);
                    set4Return.Merge(setResult);
                    #endregion

                    #region==========BHSATZ========================
                    if (set4Return.Tables["BSSATZ"].Rows.Count == 0)
                        return set4Return;
                    dwBSSATZ = set4Return.Tables["BSSATZ"].Rows[0];
                    setResult = m_WD.InsertBHSATZ(dwDispo, dwBSSATZ, "1 ", "S");
                    set4Return.Merge(setResult);
                    #endregion

                    #region==========BSFARB========================
                    if (set4Return.Tables["BHSATZ"].Rows.Count == 0)
                        return set4Return;
                    dwBHSATZ = set4Return.Tables["BHSATZ"].Rows[0];
                    bColor = dwWAFARBEN["WAFZUSATZ"].ToString();
                    setResult = m_WD.InsertBSFARB(dwBHSATZ, bColor);
                    set4Return.Merge(setResult);
                    #endregion

                    #region==========WASTKE========================
                    if (set4Return.Tables["BSFARB"].Rows.Count == 0)
                        return set4Return;
                    dwBSFARB = set4Return.Tables["BSFARB"].Rows[0];
                    m_GD = new GreigeMasterData(OracleDB, proxy);
                    setResult = m_GD.InsertWASTKE(dwWAFARBEN, dwBSFARB);
                    set4Return.Merge(setResult);
                    #endregion

                    #region==========WARPBeam========================
                    setResult = NewWARPBeam(dwDispo, dwBSFARB, numWbeam);
                    set4Return.Merge(setResult);
                    #endregion
                    return set4Return;
                }

                //分条整经

                #region==========BSSATZ========================
                dwBSFARB = setINTEX.BSFARB.NewRow();
                BSFKART = Left(dwWAFARBEN["WAFART"].ToString().Trim() + "." + dwWAFARBEN["WAFVAR"].ToString().TrimEnd() + "              ", 20);
                dwBSFARB["BSFMANDANT"] = dwWAFARBEN["WAFMANDANT"];
                dwBSFARB["BSFKART"] = BSFKART;
                dwBSFARB["BSFNEUB"] = dwWAFARBEN["WAFNEUBEN"];
                dwBSFARB["BSFNEUD"] = dwWAFARBEN["WAFNEUDAT"];
                dwBSFARB["BSFAENB"] = dwWAFARBEN["WAFNEUBEN"];
                dwBSFARB["BSFAEND"] = dwWAFARBEN["WAFNEUDAT"];
                //返回这条记录，放回界面
                setResult = m_WD.InsertBSSATZ(dwBSFARB, "W", SizingBeamYarnEnds, numWbeam);
                set4Return.Merge(setResult);
                #endregion

                #region==========BSGROE========================
                setResult = m_WD.InsertBSGROE(dwBSFARB);
                set4Return.Merge(setResult);
                #endregion

                #region==========BHSATZ========================
                if (set4Return.Tables["BSSATZ"].Rows.Count == 0)
                    return set4Return;
                dwBSSATZ = set4Return.Tables["BSSATZ"].Rows[0];
                setResult = m_WD.InsertBHSATZ(dwDispo, dwBSSATZ, "1 ", "W");
                set4Return.Merge(setResult);
                #endregion

                #region==========BSFARB========================
                if (set4Return.Tables["BHSATZ"].Rows.Count == 0)
                    return set4Return;
                dwBHSATZ = set4Return.Tables["BHSATZ"].Rows[0];
                bColor = dwWAFARBEN["WAFZUSATZ"].ToString();
                setResult = m_WD.InsertBSFARB(dwBHSATZ, bColor);
                set4Return.Merge(setResult);
                #endregion

                #region==========WASTKE========================
                if (set4Return.Tables["BSFARB"].Rows.Count == 0)
                    return set4Return;
                dwBSFARB = set4Return.Tables["BSFARB"].Rows[0];
                m_GD = new GreigeMasterData(OracleDB, proxy);
                setResult = m_GD.InsertWASTKE(dwWAFARBEN, dwBSFARB);
                set4Return.Merge(setResult);
                #endregion

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return set4Return;
        }
        public DataSet NewWARPBeam(DataRow dwDispo, DataRow dwBSFARB, int numWbeam = 0)
        {
            DataSet set4Return = new DataSet();
            DataSet setResult = new DataSet();
            DataTable tableLocal;
            WarpMasterData m_WD;
            m_WD = new WarpMasterData(OracleDB, proxy);
            string Article = "";
            DataRow dwBSFARB1 = dwBSFARB.Table.Clone().NewRow();
            dwBSFARB1.ItemArray = dwBSFARB.ItemArray;
            int defaultWarpEnds = 640;
            try
            {
                m_WD.UserID = UserID;
                Article = dwBSFARB["BSFKART"].ToString().Trim();
                for (int bi = 1; bi < numWbeam + 1; bi++)
                {
                    dwBSFARB1["BSFKART"] = Left(Article + "-" + bi.ToString() + "                          ", 20);
                    setResult = m_WD.InsertBSSATZ(dwBSFARB1, "W", defaultWarpEnds);
                    set4Return.Merge(setResult);
                    if (set4Return.Tables["BSSATZ"].Rows.Count == 0)
                        return set4Return;
                    DataRow dwBSSATZ = setResult.Tables["BSSATZ"].Rows[0];
                    setResult = m_WD.InsertBHSATZ(dwDispo, dwBSSATZ, "1 ", "W");
                    set4Return.Merge(setResult);
                    if (set4Return.Tables["BHSATZ"].Rows.Count == 0)
                        return set4Return;
                    DataRow dwBHSATZ = setResult.Tables["BHSATZ"].Rows[0];
                    string bColor = dwBSFARB["BSFKFARBE"].ToString();
                    setResult = m_WD.InsertBSFARB(dwBHSATZ, bColor);
                    set4Return.Merge(setResult);
                    if (set4Return.Tables["BSFARB"].Rows.Count == 0)
                        return set4Return;
                    dwBSFARB1 = setResult.Tables["BSFARB"].Rows[0];
                    setResult = m_WD.InsertBASTKE(dwBSFARB, dwBSFARB1, bi);
                    set4Return.Merge(setResult);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return set4Return;
        }
        private bool ValidateWASTAMM(DataRow dwInput, ref string MsgValidate)
        {
            bool flagValidate = false;
            try
            {
                if (dwInput["WAMANDANT"].ToString().Trim() == "")
                {
                    MsgValidate = "MANDANT 为空";
                    return flagValidate;
                }
                if (dwInput["WAART"].ToString().Trim() == "")
                {
                    MsgValidate = "WAART 为空";
                    return flagValidate;
                }
                if (dwInput["WAART"].ToString().Trim() == "")
                {
                    MsgValidate = "WAART 为空";
                    return flagValidate;
                }
                if (dwInput["WAVAR"].ToString().Trim() == "")
                {
                    //MsgValidate = "WAVAR 为空";
                    //return flagValidate;
                }

                if (dwInput["WADART"].ToString().Trim() == "")
                {
                    MsgValidate = "计划物料不能为空";
                    return flagValidate;
                }
                if (dwInput["WABEZ"].ToString().Trim() == "")
                {
                    MsgValidate = "描述不能为空";
                    //return flagValidate;
                }
                if (dwInput["WARWBRT"].ToString().Trim() == "0")
                {
                    MsgValidate = "坯布幅宽不能为0";
                    return flagValidate;
                }
                if (dwInput["WAFBRTL"].ToString().Trim() == "0")
                {
                    MsgValidate = "成品幅宽不能为0";
                    return flagValidate;
                }
                if (dwInput["WARFDDIK"].ToString().Trim() == "0")
                {
                    MsgValidate = "坯布经密>0";
                    return flagValidate;
                }

                if (dwInput["WARFDDIS"].ToString().Trim() == "0")
                {
                    MsgValidate = "坯布纬密>0";
                    return flagValidate;
                }
                if (dwInput["WAFFDDIK"].ToString().Trim() == "0")
                {
                    MsgValidate = "成品经密>0";
                    return flagValidate;
                }
                if (dwInput["WAFFDDIS"].ToString().Trim() == "0")
                {
                    MsgValidate = "成品纬密>0";
                    return flagValidate;
                }
                if (dwInput["WABIND"].ToString().Trim() == "")
                {
                    MsgValidate = "请输入插筘法";
                    return flagValidate;
                }
                if (dwInput["WAEINZNR"].ToString().Trim() == "0")
                {
                    MsgValidate = "请输入花型";
                    return flagValidate;
                }
                if (dwInput["WALAEAEND"].ToString().Trim() == "0")
                {
                    MsgValidate = "整理缩率必须输入";
                    return flagValidate;
                }
                if (dwInput["WATSDSCH"].ToString().Trim() == "0")
                {
                    dwInput["WATSDSCH"] = 7800;
                    MsgValidate = "每卷千纬数要仔细计算";
                }
                long WARGRLFD = System.Convert.ToInt64(dwInput["WARGRLFD"].ToString());//坯布克重 398
                long WARWBRT = System.Convert.ToInt64(dwInput["WARWBRT"].ToString());//坯布幅宽 1600
                string WARGRQM = dwInput["WARGRQM"].ToString();//255
                WARGRQM = System.Math.Round(WARGRLFD / (0.001 * WARWBRT), 0).ToString();
                dwInput["WARGRQM"] = WARGRQM;

                long WARSTDLG = System.Convert.ToInt64(dwInput["WARSTDLG"].ToString());//标准匹长 200000
                string WARSTDGW = dwInput["WARSTDGW"].ToString();//标准匹重	7960
                WARSTDGW = System.Math.Round(WARGRLFD * WARSTDLG * 0.001, 0).ToString();
                dwInput["WARSTDGW"] = WARSTDGW;

                long WARFDDIS = System.Convert.ToInt64(dwInput["WARFDDIS"].ToString());//坯布纬密 3200
                string WATSDSCH = dwInput["WATSDSCH"].ToString();//每卷千纬数 2520 252	=四舍五入（10×每卷匹长×100*坯布纬密/2.54/1000）
                WATSDSCH = System.Math.Round(10 * WARSTDLG * 0.001 * 100 * WARFDDIS * 0.01 / 2.54 * 0.001, 0).ToString();
                dwInput["WATSDSCH"] = WATSDSCH;

                long WAFGRLFD = System.Convert.ToInt64(dwInput["WAFGRLFD"].ToString());//克重 398
                long WAFSTDLG = System.Convert.ToInt64(dwInput["WAFSTDLG"].ToString());//标准匹长 200000
                long WAFBRTL = System.Convert.ToInt64(dwInput["WAFBRTL"].ToString());//幅宽 1600
                string WAFGRQM = dwInput["WAFGRQM"].ToString();//255
                WAFGRQM = System.Math.Round(WAFGRLFD / (0.001 * WAFBRTL), 0).ToString();
                dwInput["WAFGRQM"] = WAFGRQM;
                
                string WAFSTDGW = dwInput["WAFSTDGW"].ToString();//标准匹重	7960
                WAFSTDGW = System.Math.Round(WAFGRLFD * WAFSTDLG * 0.001 * 0.1, 0).ToString();
                dwInput["WAFSTDGW"] = WAFSTDGW;
                flagValidate = true;
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return flagValidate;
        }
        private bool ValidateWTGEW(DataRow dwInput, ref string MsgValidate)
        {
            bool flagValidate = false;
            try
            {

                if (dwInput["WTGMANDANT"].ToString().Trim() == "")
                {
                    MsgValidate = "MANDANT 为空";
                    return flagValidate;
                }
                if (dwInput["WTGART"].ToString().Trim() == "")
                {
                    MsgValidate = "ART 为空";
                    return flagValidate;
                }
                if (dwInput["WTGVAR"].ToString().Trim() == "")
                {
                    //MsgValidate = "WAART 为空";
                    //return flagValidate;
                }

                if (dwInput["WTGWBBRT"].ToString().Trim() == "0")
                {
                    MsgValidate = "筘幅>0";
                    return flagValidate;
                }
                if (dwInput["WTGWBF"].ToString().Trim() == "0")
                {
                    MsgValidate = "筘齿密度>0";
                    return flagValidate;
                }
                if (dwInput["WTGFDISM"].ToString().Trim() == "0")
                {
                    MsgValidate = "机上纬密>0";
                    return flagValidate;
                }
                if (dwInput["WTGFDLGS"].ToString().Trim() == "0")
                {
                    MsgValidate = "底纬幅宽>0";
                    return flagValidate;
                }

                if (dwInput["WTGFDLFS"].ToString().Trim() == "0")
                {
                    //MsgValidate = "坯布纬密>0";
                    //return flagValidate;
                }
                if (dwInput["WTGSFLG"].ToString().Trim() == "")
                {
                    MsgValidate = "请输入纬向排花>0";
                    return flagValidate;
                }
                if (dwInput["WTGSMTRS"].ToString().Trim() == "0")
                {
                    //MsgValidate = "成品纬密>0";
                    //return flagValidate;
                }
                flagValidate = true;
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return flagValidate;
        }
     
        public void SaveBASTGA(DataSet setData)
        {
            DataSet set4Return = new DataSet();
            DataSet setResult = new DataSet();
            DataTable tableLocal;
            try
            {
                WarpMasterData m_Wm = new WarpMasterData(OracleDB, proxy);
                foreach (DataRow dwBSSATZ in setData.Tables["BSSATZ"].Rows)
                {
                    m_Wm.UpdateBSSATZ(dwBSSATZ);
                }
                foreach (DataRow dwBASTGA in setData.Tables["BASTGA"].Rows)
                {
                    m_Wm.InsertBASTGA(dwBASTGA);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }

        public void SaveWASTGA(DataTable tbWASTGA = null)
        {
            DataSet set4Return = new DataSet();
            DataSet setResult = new DataSet();
            DataTable tableLocal;
            try
            {
                GreigeMasterData m_Wg = new GreigeMasterData(OracleDB, proxy);
                foreach (DataRow dwWASTGA in tbWASTGA.Rows)
                {
                    m_Wg.InsertWASTGA(dwWASTGA);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }

        public DataSet GetData(DataRow dwART,string color,string finish)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            string Article = (dwART["WAART"].ToString().Trim() + "/" + dwART["WAVAR"].ToString().Trim() + "/" + Convert8859P1ToGB2312(dwART["WAFZUSATZ"].ToString().Trim())).Trim();
            try
            {
                setReturn.Clear();
                GreigeMasterData m_Data1 = new GreigeMasterData(OracleDB, proxy);
                setReturn = m_Data1.LoadTableStructure(setReturn);
                EventDispatcher.Instance.RaiseStatus("开始品种:" +Article+ "信息", StatusEventType.StartProgress); 
                dwART["WAFART"] = dwART["WAART"];
                dwART["WAFVAR"] = dwART["WAVAR"];
                dwART["WAFZUSATZ"] = dwART["WAFZUSATZ"];
                setResult = m_Data1.GetData(dwART,color,finish);
                setReturn.Merge(setResult);

                EventDispatcher.Instance.RaiseStatus("品种" + Article + "主数据已经读取", StatusEventType.RunningProgress); 
                #region WarpMasterData
                WarpMasterData m_Wm = new WarpMasterData();
                m_Wm.OracleDB = this.OracleDB;
                m_Wm.proxy = this.proxy;
                setReturn = m_Wm.LoadTableStructure(setReturn);
                if (setReturn.Tables.Contains("WASTKE"))
                {
                    foreach (DataRow dwWASTKE in setReturn.Tables["WASTKE"].Rows)
                    {
                        dwART["BSFKART"] = dwWASTKE["WAKKART"];
                        dwART["BSFKVAR"] = dwWASTKE["WAKKVAR"];
                        dwART["BSFKFARBE"] = m_Wm.GetGB2312Value(dwWASTKE, "WAKKFARBE");
                        setResult = m_Wm.GetData(dwART);
                        setReturn.Merge(setResult);
                        EventDispatcher.Instance.RaiseStatus("品种" + Article + "织轴信息已经读取", StatusEventType.RunningProgress); 
                    }
                }
                DataSet setTemp = new DataSet();
                if (setReturn.Tables.Contains("BASTKE"))
                {
                    foreach (DataRow dwBASTKE in setReturn.Tables["BASTKE"].Rows)
                    {
                        setResult = new DataSet();
                        //WAKKART              WAKKVAR WAKKFARBE
                        dwART["BSFKART"] = dwBASTKE["BAKKART"];
                        dwART["BSFKVAR"] = dwBASTKE["BAKKVAR"];
                        dwART["BSFKFARBE"] = m_Wm.GetGB2312Value(dwBASTKE, "BAKKFARBE");
                        setResult = m_Wm.GetData(dwART);
                        setTemp.Merge(setResult);
                        EventDispatcher.Instance.RaiseStatus("品种" + Article + "经轴信息已经读取", StatusEventType.RunningProgress); 
                    }
                    setReturn.Merge(setTemp);
                }
                #endregion
                return setReturn;
                #region YarnMasterData
                YarnMasterData m_YM = new YarnMasterData();
                m_YM.OracleDB = this.OracleDB;
                m_YM.proxy = this.proxy;
                setResult = new DataSet();
                setResult = m_YM.LoadTableStructure(setResult);
                setReturn.Merge(setResult);
                bool flag = true;
                string YarnArt;
                string YarnVar;
                string YarnColor;
                DataRow dwGSCOLOR;
                DataTable dtGSCOLOR;
                dtGSCOLOR = setReturn.Tables["GSCOLOR"].Clone();
                while (flag)
                {
                    #region WASTGA
                    foreach (DataRow dwWASTGA in setReturn.Tables["WASTGA"].Rows)
                    {
                        //WAGGART              WAGGVAR WAGGFARBE  
                        YarnArt = dwWASTGA["WAGGART"].ToString();
                        YarnVar = dwWASTGA["WAGGVAR"].ToString();
                        YarnColor = m_YM.GetGB2312Value(dwWASTGA, "WAGGFARBE");
                        if (!m_YM.YarnExist(setReturn.Tables["GSDAT"], YarnArt, YarnVar))
                        {
                            if (!m_YM.YarnExist(dtGSCOLOR, YarnArt, YarnVar))
                            {
                                dwGSCOLOR = dtGSCOLOR.Rows.Add();
                                dwGSCOLOR["GSCART"] = YarnArt;
                                dwGSCOLOR["GSCVAR"] = YarnVar;
                                dwGSCOLOR["GSCFARBE"] = YarnColor;
                            }
                        }
                    }
                    #endregion

                    #region BASTGA
                    foreach (DataRow dwBASTGA in setReturn.Tables["BASTGA"].Rows)
                    {

                        //GSCOLOR/  GSCART               GSCVAR GSCFARBE  
                        YarnArt = dwBASTGA["BAGGART"].ToString();
                        YarnVar = dwBASTGA["BAGGVAR"].ToString();
                        YarnColor = m_YM.GetGB2312Value(dwBASTGA, "BAGGFARBE");
                        if (!m_YM.YarnExist(setReturn.Tables["GSDAT"], YarnArt, YarnVar))
                        {
                            if (!m_YM.YarnExist(dtGSCOLOR, YarnArt, YarnVar))
                            {
                                dwGSCOLOR = dtGSCOLOR.Rows.Add();
                                dwGSCOLOR["GSCART"] = YarnArt;
                                dwGSCOLOR["GSCVAR"] = YarnVar;
                                dwGSCOLOR["GSCFARBE"] = YarnColor;
                            }
                        }
                    }
                    #endregion

                    #region GASTGA
                    foreach (DataRow dwGASTGA in setReturn.Tables["GASTGA"].Rows)
                    {

                        YarnArt = dwGASTGA["GAGGART"].ToString();
                        YarnVar = dwGASTGA["GAGGVAR"].ToString();
                        YarnColor = dwGASTGA["GAGGFARBE"].ToString();
                        if (!m_YM.YarnExist(setReturn.Tables["GSDAT"], YarnArt, YarnVar))
                        {
                            if (!m_YM.YarnExist(dtGSCOLOR, YarnArt, YarnVar))
                            {
                                dwGSCOLOR = dtGSCOLOR.Rows.Add();
                                dwGSCOLOR["GSCART"] = YarnArt;
                                dwGSCOLOR["GSCVAR"] = YarnVar;
                                dwGSCOLOR["GSCFARBE"] = YarnColor;
                            }
                        }
                    }
                    #endregion
                    flag = false;
                    foreach (DataRow dwYan in dtGSCOLOR.Rows)
                    {
                        flag = true;
                        setResult = m_YM.BuildYarnMasterData(setResult, dwYan);
                        setReturn.Merge(setResult);
                    }
                    dtGSCOLOR.Clear();

                }
                #endregion
                EventDispatcher.Instance.RaiseStatus("品种" + Article + " 已读取纱线信息", StatusEventType.RunningProgress); 
                #region PatternMasterData
                PatternMasterData m_PD = new PatternMasterData(OracleDB, proxy);
                setResult = m_PD.LoadTableStructure(setResult);
                setReturn.Merge(setResult);
                DataTable dtPattern = null;
                if (setReturn.Tables.Contains("Pattern"))
                {
                    setReturn.Tables["Pattern"].Clear();
                }
                else
                {
                    setReturn.Tables.Add(tbPattern);
                }

                dtPattern = setReturn.Tables["Pattern"];
                DataRow dwPattern;

                #region WarpPattern
                foreach (DataRow dwTmp in setReturn.Tables["BSSATZ"].Rows)
                {
                    continue;
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTSAER";
                    dwPattern["PatternType"] = "WarpPattern";
                    dwPattern["PatternKeyName"] = "WTBSRFNR";
                    dwPattern["PatternKey"] = dwTmp["BSSRFNR"].ToString().Trim();
                }
                #endregion

                #region SelvagePattern
                foreach (DataRow dwTmp in setReturn.Tables["WASTKE"].Rows)
                {
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTLEIST";
                    dwPattern["PatternType"] = "SelvageLeftPattern";
                    dwPattern["PatternKeyName"] = "WTLLEIST";
                    dwPattern["PatternKey"] = dwTmp["WAKLLEIST"].ToString().Trim();
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTLEIST";
                    dwPattern["PatternType"] = "SelvageRightPattern";
                    dwPattern["PatternKeyName"] = "WTLLEIST";
                    dwPattern["PatternKey"] = dwTmp["WAKRLEIST"].ToString().Trim();
                }
                #endregion

                #region WeaveRepeat /Denting
                foreach (DataRow dwTmp in setReturn.Tables["WASTAMM"].Rows)
                {
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "SDDAT";
                    dwPattern["PatternType"] = "WeaveRepeat";
                    dwPattern["PatternKeyName"] = "SDKEY";
                    //select * from sddat where SDSA='0109' AND SDKEY Like '%4226%V'
                    dwPattern["PatternKey"] = dwTmp["WABIND"].ToString().Trim();

                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTEINZ";
                    dwPattern["PatternType"] = "Denting";
                    dwPattern["PatternKeyName"] = "WTEEINZNR";
                    dwPattern["PatternKey"] = dwTmp["WAEINZNR"].ToString().Trim();

                }
                #endregion

                #region WeftPattern
                foreach (DataRow dwTmp in setReturn.Tables["WTGEW"].Rows)
                {
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTSCHUSS";
                    dwPattern["PatternType"] = "WeftPattern";
                    dwPattern["PatternKeyName"] = "WTSSFLGNR";
                    dwPattern["PatternKey"] = dwTmp["WTGSFLG"].ToString().Trim();

                }
                #endregion

                #region DraftingNumber

                foreach (DataRow dwTmp in setReturn.Tables["WASTPASS"].Rows)
                {
                    dwPattern = dtPattern.Rows.Add();
                    dwPattern["PatternTable"] = "WTPASS";
                    dwPattern["PatternType"] = "DraftingNumber";
                    dwPattern["PatternKeyName"] = "WTPPASSNR";
                    dwPattern["PatternKey"] = dwTmp["WSPPASS"].ToString().Trim();

                }
                #endregion

                foreach (DataRow dwPatterns in dtPattern.Rows)
                {
                    setResult = m_PD.BuildPatternMasterData(setResult, dwPatterns);
                    EventDispatcher.Instance.RaiseStatus("品种" + Article +dwPattern["PatternTable"].ToString()+ " 已读花型线信息", StatusEventType.RunningProgress); 
                    setReturn.Merge(setResult);
                }
                #endregion
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            
            return setReturn;
        }
        public DataSet LoadSetDispo(string setID="")
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                string filePath = Path.Combine(PathHelper.ApplicationPath, "SETDISPO.XML");
                if (System.IO.File.Exists(filePath))
                {
                    setResult.ReadXml(filePath);
                    setResult.Tables[0].TableName = "DATADISPO";
                    if (setID.Trim().Length > 0)
                    {
                        DataRow[] rowsDISPO = setResult.Tables["DATADISPO"].Select("ID='" + setID + "'");
                        setReturn.Merge(rowsDISPO);
                    }
                    else
                    {
                        setReturn.Merge(setResult);
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public void SaveSetDispo(DataTable tbDispo)
        {
            DataSet setDispo = new DataSet();
            
            try
            {
                setDispo.Merge(tbDispo);
                string filePath = Path.Combine(PathHelper.ApplicationPath, "SETDISPO.XML");
                if (System.IO.File.Exists(filePath))
                {
                    System.IO.File.Delete(filePath);
                    setDispo.WriteXml(filePath); 
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public DataSet LoadSetWEAVE()
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                string filePath = Path.Combine(PathHelper.ApplicationPath, "SETWEAVE.XML");
                if (System.IO.File.Exists(filePath))
                {
                    setResult.ReadXml(filePath); 
                    setReturn.Merge(setResult);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet QueryWeave(DataSet setWEAVE, string PGAART, string DFAART)
        {
            DataSet setReturn = new DataSet();
            DataRow[] tempPEGPLAN, tempDRAFTING;
            try
            {
                /*
                DataTable tempPEGPLAN = setWEAVE.Tables["PEGPLAN"].Clone(); 
                DataRow dwPEGPLAN = tempPEGPLAN.NewRow();

                var query = from DataRow dwTemp in setWEAVE.Tables["PEGPLAN"].AsEnumerable()
                            where dwTemp["PGAART"].ToString() == PGAART
                            select dwTemp;
                foreach (DataRow dwTemp in query)
                {
                    dwPEGPLAN = tempPEGPLAN.NewRow();
                    dwPEGPLAN.ItemArray = dwTemp.ItemArray;
                    tempPEGPLAN.Rows.Add(dwPEGPLAN);
                }
                */
                tempPEGPLAN = setWEAVE.Tables["PEGPLAN"].Select("PGAART='" + PGAART + "'");
                setReturn.Merge(tempPEGPLAN);

             
                /*   DataTable tempDRAFTING = setWEAVE.Tables["DRAFTING"].Clone();
                DataRow dwDRAFTING = tempDRAFTING.NewRow();

                var query1 = from DataRow dwTemp in setWEAVE.Tables["DRAFTING"].AsEnumerable()
                             where dwTemp["DFAART"].ToString() == DFAART
                             select dwTemp;
                foreach (DataRow dwTemp in query1)
                {
                    dwDRAFTING = tempDRAFTING.NewRow();
                    dwDRAFTING.ItemArray = dwTemp.ItemArray;
                    tempDRAFTING.Rows.Add(dwDRAFTING);
                }
                */
                tempDRAFTING = setWEAVE.Tables["DRAFTING"].Select("DFAART='" + DFAART + "'");
                setReturn.Merge(tempDRAFTING);

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public void SaveSetWEAVE(DataSet setWEAVE)
        {
            
            try
            {
                string filePath = Path.Combine(PathHelper.ApplicationPath, "SETWEAVE.XML");
                if (System.IO.File.Exists(filePath))
                {
                 //   File.Delete(filePath);
                }
                setWEAVE.WriteXml(filePath);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
         
        }

        public void CreateWASTAMM(DataRow dwUI, ref INTEXDataSet setData, string color, string finish)
        {
            DataRow dwWDECK = null;
            try
            {
                #region===========WASTAMM=================
                if (setData.WDECK.Rows.Count > 0)
                {
                    dwWDECK = setData.WDECK.Rows[0];
                }
                DataRow dwWASTAMM = setData.WASTAMM.NewRow();
                dwWASTAMM["WAMANDANT"] = "00";
                dwWASTAMM["WAART"] = dwUI["WAART"];
                dwWASTAMM["WAVAR"] = dwUI["WAVAR"];
                dwWASTAMM["WABEZ"] = "  ";
                dwWASTAMM["WARBEM"] = "  ";
                string WABIND = dwWASTAMM["WAART"].ToString().Trim() + "." + dwWASTAMM["WAVAR"].ToString().Trim() + "                               ";
                dwWASTAMM["WABIND"] = Left(WABIND, 15);

                foreach (DataColumn dc in setData.WASTAMM.Columns)
                {
                    if (dc.DataType == System.Type.GetType("System.Decimal"))
                    {
                        dwWASTAMM[dc.ColumnName] = 0;
                    }
                }
                #region===========TESTING DATA============
                dwWASTAMM["WABEZ"] = "                                        ";
                dwWASTAMM["WARBEM"] = "                                        ";
                dwWASTAMM["WARWBRT"] = 1600;// "坯布幅宽不能为0";
                dwWASTAMM["WAFBRTL"] = 1600;// "成品幅宽不能为0";
                dwWASTAMM["WARFDDIK"] = 12000;// "坯布经密>0";
                dwWASTAMM["WARFDDIS"] = 8000;// "坯布纬密>0";
                dwWASTAMM["WAFFDDIK"] = 12000;// "成品经密>0";
                dwWASTAMM["WAFFDDIS"] = 8000;// "成品纬密>0";
                dwWASTAMM["WAEINZNR"] = "2              ";// "穿筘法";
                dwWASTAMM["WALAEAEND"] = 500;// "缩率";
                dwWASTAMM["WAFDDIM"] = "INC";// "缩率";
                dwWASTAMM["WAFSTDLG"] = 200000;
                dwWASTAMM["WARSTDLG"] = 200000;

                dwWASTAMM["WAFFERTKZ"] = "E";
                dwWASTAMM["WARFERTKZ"] = "E";
                dwWASTAMM["WAGASTA"] = "V";
                dwWASTAMM["WAMASTA"] = "V";
                dwWASTAMM["WAKESTA"] = "V";
                dwWASTAMM["WAMATPRF"] = " ";
                dwWASTAMM["WABRTPRF"] = " ";
                dwWASTAMM["WASTKGP"] = " ";
                dwWASTAMM["WASCHLIP"] = " ";
                dwWASTAMM["WASCHLIA"] = " ";
                dwWASTAMM["WALIEFNR"] = "        ";
                dwWASTAMM["WAEG"] = "N";
                dwWASTAMM["WAGFKZ"] = "J";
                dwWASTAMM["WAFRBST"] = "C";
                
                dwWASTAMM["WAPROGRP"] = "HWD";
                dwWASTAMM["WAARTGRP"] = "HWD";
                dwWASTAMM["WARSTDGW"] = "31400";
                dwWASTAMM["WAFSTDGW"] = "31400";
                dwWASTAMM["WARGRQM"] = 98;
                dwWASTAMM["WAFGRQM"] = 98;

                dwWASTAMM["WARGRLFD"] = 157;
                dwWASTAMM["WAFGRLFD"] = 157;
                dwWASTAMM["WARGWTOL"] = 200;
                dwWASTAMM["WATSDSCH"] = 3940;

                #endregion
                dwWASTAMM["WADART"] = dwUI["WAART"];
                dwWASTAMM["WADVAR"] = dwUI["WAVAR"];
                if (dwWDECK != null)
                {
                    dwWASTAMM["WADART"] = dwWDECK["WDART"];
                    dwWASTAMM["WADVAR"] = dwWDECK["WDVAR"];
                }
                dwWASTAMM["WAAENB"] = dwUI["WANEUB"];
                dwWASTAMM["WAAEND"] = dwUI["WANEUD"];
                dwWASTAMM["WANEUB"] = dwUI["WANEUB"];
                dwWASTAMM["WANEUD"] = dwUI["WANEUD"];
                setData.WASTAMM.Rows.Add(dwWASTAMM);
                #endregion

                #region===========WTGEW===================

                setData.Merge(m_GM.NewWS22(dwUI));
                #endregion

                #region===========WASTPASS=================
                setData.Merge(m_GM.NewWASTPASS(dwUI));
                #endregion

                #region===========WAFARBEN=================
                setData.Merge(m_GM.NewWAFARBEN(dwUI, "C", color));
                setData.Merge(m_GM.NewWAFARBEN(dwUI, "B", finish));
                #endregion

                #region===========SAVE=================
                SaveWASTAMM(setData, color, finish);
                #endregion
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        public bool SaveWASTAMM(DataSet setData, string color, string finish)
        {
            DataSet set4Return = new DataSet();
            DataSet setResult = new DataSet();
            DataTable tableLocal;
            DataTable tbWAFARBEN = null;
            DataRow dwInput;
            bool flagValidate = false;
            string MsgValidate = "";
            DataRow dwWTGEW = null, dwWASTAMM = null, dwWASTPASS = null, dwVAART = null, dwVAFARBEN = null, dwWDECK = null;
            DataRow dwDispo = setData.Tables["DATADISPO"].Rows[0];
            try
            {
                #region==========VALIDATE========================

                if (setData.Tables["WASTAMM"].Rows.Count == 0)
                {
                    EventDispatcher.Instance.RaiseStatus("WASTAMM没有数据", StatusEventType.StopProgress);
                    return false;
                }
                dwWASTAMM = setData.Tables["WASTAMM"].Rows[0];
                if (setData.Tables["WTGEW"].Rows.Count == 0)
                {
                    EventDispatcher.Instance.RaiseStatus("WTGEW没有数据", StatusEventType.StopProgress);
                    return false;
                }
                dwWTGEW = setData.Tables["WTGEW"].Rows[0];

                if (setData.Tables["WASTPASS"].Rows.Count == 0)
                {
                    EventDispatcher.Instance.RaiseStatus("WASTPASS没有数据", StatusEventType.StopProgress);
                    return false;
                }
                dwWASTPASS = setData.Tables["WASTPASS"].Rows[0];
                if (setData.Tables.Contains("VAART"))
                {
                    if (setData.Tables["VAART"].Rows.Count > 0)
                    {
                        dwVAART = setData.Tables["VAART"].Rows[0];
                    }
                    if (setData.Tables["VAFARBEN"].Rows.Count > 0)
                    {
                        dwVAFARBEN = setData.Tables["VAFARBEN"].Rows[0];
                    }
                    if (setData.Tables["WDECK"].Rows.Count > 0)
                    {
                        dwWDECK = setData.Tables["WDECK"].Rows[0];
                    }
                }
                if (setData.Tables["WAFARBEN"].Rows.Count == 0)
                {
                    EventDispatcher.Instance.RaiseStatus("WAFARBEN没有数据", StatusEventType.StopProgress);
                    return false;
                }
                tbWAFARBEN = setData.Tables["WAFARBEN"];

                flagValidate = ValidateWASTAMM(dwWASTAMM, ref MsgValidate);
                if (!flagValidate)
                {
                    EventDispatcher.Instance.RaiseStatus("ValidateWASTAMM未通过检查:" + MsgValidate, StatusEventType.StopProgress);
                    return false;
                }
                dwWTGEW = setData.Tables["WTGEW"].Rows[0];
                flagValidate = ValidateWTGEW(dwWTGEW, ref MsgValidate);
                if (!flagValidate)
                {
                    MessageBox.Show("请完善资料::" + MsgValidate);
                    return false;
                }
                #endregion
                EventDispatcher.Instance.RaiseStatus("开始保存InsertWASTAMM", StatusEventType.StartProgress);
                setResult = m_GM.InsertWASTAMM(dwWASTAMM, dwDispo);
                set4Return.Merge(setResult);

                EventDispatcher.Instance.RaiseStatus("开始保存InsertWABIND", StatusEventType.RunningProgress);
                m_GM.InsertWABIND(dwWASTAMM["WABIND"].ToString());

                EventDispatcher.Instance.RaiseStatus("开始保存InsertWTGEW", StatusEventType.RunningProgress);
                setResult = m_GM.InsertWTGEW(dwWTGEW);
                set4Return.Merge(setResult);

                EventDispatcher.Instance.RaiseStatus("开始保存InsertWASTPASS", StatusEventType.RunningProgress);
                setResult = m_GM.InsertWASTPASS(dwWASTPASS);
                set4Return.Merge(setResult);

                EventDispatcher.Instance.RaiseStatus("开始保存InsertWTPASS", StatusEventType.RunningProgress);
                m_GM.InsertWTPASS(dwWASTPASS["WSPPASS"].ToString());

                EventDispatcher.Instance.RaiseStatus("开始保存InsertWAFARBEN", StatusEventType.RunningProgress);
                setResult = m_GM.InsertWAFARBEN(tbWAFARBEN);
                set4Return.Merge(setResult);
                if (dwVAART != null)
                {
                    EventDispatcher.Instance.RaiseStatus("开始保存UpdateVA0710", StatusEventType.RunningProgress);
                    setResult = m_GM.UpdateVA0710(tbWAFARBEN, dwWASTAMM, dwVAART, dwVAFARBEN, color, finish);

                    EventDispatcher.Instance.RaiseStatus("开始保存UpdateWDECK", StatusEventType.RunningProgress);
                    m_GM.UpdateWDECK(dwWDECK, dwWASTAMM);
                }

                EventDispatcher.Instance.RaiseStatus("保存完成", StatusEventType.StopProgress);
                //VAABESTANDF
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return true;
        }
    }
}